package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.CategoryDTO;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.pojo.Category;
import com.sky.pojo.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import com.sky.service.admin.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类相关接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 添加分类,分类名字唯一,有只有2种套餐
     * @param categoryDTO
     * @return
     */
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("检验{}",categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @param name
     * @param type
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(

            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam (defaultValue = "10") Integer pageSize,String name,
            Integer type){
        log.info("page:{},pageSize:{},name:{}",page,pageSize,name,type);
        PageResult pageResult = categoryService.pageQuery(page, pageSize, name,type);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteById(Long id){
        log.info("删除分类:{}",id);
        categoryService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类:{}",categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }

    /**
     * 开启或者关闭禁用状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    public Result startOrStop(@RequestParam Long  id,@PathVariable Integer status){
        log.info("修改分类状态:{},id:{}",status,id);
        categoryService.startOrstop(id, status);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(Integer type){
        log.info("查询分类:{}",type);
        List<Category> list = categoryService.findList(type);

        return Result.success(list);
    }




}
